package org.jeecg.modules.purchase.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.system.vo.LoginUser;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        this.setFieldValByName("updateTime",new Date(),metaObject);
        this.setFieldValByName("updateBy",sysUser.getRealname(),metaObject);
        this.setFieldValByName("createBy",sysUser.getRealname(),metaObject);
        this.setFieldValByName("createTime",new Date(),metaObject);

    }

    @Override
    public void updateFill(MetaObject metaObject) {
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        this.setFieldValByName("updateTime",new Date(),metaObject);
        this.setFieldValByName("updateBy",sysUser.getRealname(),metaObject);

    }
}
